using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Platform.algorithm;

namespace Platform
{
    public partial class Setting : Form
    {
        public Setting()
        {
            InitializeComponent();
        }

        private void Setting_Load(object sender, EventArgs e)
        {
            if (GlobalSetting.KnowledgeSet == KONWLEDGESET.GB18030)
                checkBox1.Checked = true;
            if (GlobalSetting.KnowledgeSet == KONWLEDGESET.GB2312)
                checkBox2.Checked = true;
            if (GlobalSetting.KnowledgeSet == KONWLEDGESET.GB18030_2005)
                checkBox7.Checked = true;
            if (GlobalSetting.OrderType == ORDERTYPE.CHINESE_DESC)
                checkBox3.Checked = true;
            if (GlobalSetting.OrderType == ORDERTYPE.BASEUNIT_DESC)
                checkBox4.Checked = true;
            if (GlobalSetting.StructCodeLast)
                checkBox5.Checked = true;
            else checkBox6.Checked = true;
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                checkBox2.Checked = false;
                checkBox7.Checked = false;
            }
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox2.Checked)
            {
                checkBox1.Checked = false;
                checkBox7.Checked = false;
            }
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox3.Checked)
                checkBox4.Checked = false;
            else checkBox4.Checked = true;
        }

        private void checkBox4_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox4.Checked)
                checkBox3.Checked = false;
            else checkBox3.Checked = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            KONWLEDGESET ks = KONWLEDGESET.GB18030;
            if (checkBox1.Checked)
                ks = KONWLEDGESET.GB18030;
            else if (checkBox2.Checked)
                ks = KONWLEDGESET.GB2312;
            else if (checkBox7.Checked)
                ks = KONWLEDGESET.GB18030_2005;
            else ks = KONWLEDGESET.GB18030;

            if (GlobalSetting.KnowledgeSet != ks)
            {                
                GlobalSetting.KnowledgeSet = ks;
                KnowledgeBase.Reload();
            }
            GlobalSetting.OrderType = checkBox3.Checked ? ORDERTYPE.CHINESE_DESC : ORDERTYPE.BASEUNIT_DESC;
            GlobalSetting.StructCodeLast = checkBox5.Checked;
            Close();
        }

        private void checkBox5_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox5.Checked)
                checkBox6.Checked = false;
            else checkBox6.Checked = true;
        }

        private void checkBox6_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox6.Checked)
                checkBox5.Checked = false;
            else checkBox5.Checked = true;
        }

        private void checkBox7_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox7.Checked)
            {
                checkBox1.Checked = false;
                checkBox2.Checked = false;
            }
        }
    }
}